using Newtonsoft.Json;
using System.Collections.Generic;

namespace BanZuiCloudControlAgent.Core.Mqtt.Models
{
    /// <summary>
    /// 采集上报消息负载模型
    /// </summary>
    public class CollectReportPayloadModel
    {
        /// <summary>
        /// 采集类型
        /// </summary>
        [JsonProperty("collectType")]
        public string CollectType { get; set; }

        /// <summary>
        /// 采集任务ID
        /// </summary>
        [JsonProperty("collectTaskId")]
        public string CollectTaskId { get; set; }

        /// <summary>
        /// 批次号
        /// </summary>
        [JsonProperty("batchNumber")]
        public int BatchNumber { get; set; }

        /// <summary>
        /// 总批次数
        /// </summary>
        [JsonProperty("totalBatches")]
        public int TotalBatches { get; set; }

        /// <summary>
        /// 采集数量
        /// </summary>
        [JsonProperty("collectCount")]
        public int CollectCount { get; set; }

        /// <summary>
        /// QQ号码
        /// </summary>
        [JsonProperty("qqNumber")]
        public string QQNumber { get; set; }

        /// <summary>
        /// 采集数据
        /// </summary>
        [JsonProperty("collectData")]
        public List<object> CollectData { get; set; }

        /// <summary>
        /// 是否为最后一批
        /// </summary>
        [JsonProperty("isLastBatch")]
        public bool IsLastBatch { get; set; }

        /// <summary>
        /// 总采集数量
        /// </summary>
        [JsonProperty("totalCollected")]
        public int TotalCollected { get; set; }
    }

    /// <summary>
    /// 采集上报消息模型
    /// </summary>
    public class CollectReportModel : BaseMessageModel
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public CollectReportModel() : base()
        {
            MessageType = MessageTypeConstants.COLLECT_REPORT;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="deviceCode">设备码</param>
        /// <param name="payload">采集上报负载</param>
        public CollectReportModel(string deviceCode, CollectReportPayloadModel payload)
            : base(MessageTypeConstants.COLLECT_REPORT, deviceCode, payload)
        {
        }

        /// <summary>
        /// 获取采集上报负载
        /// </summary>
        /// <returns>采集上报负载</returns>
        public CollectReportPayloadModel GetPayload()
        {
            return Payload as CollectReportPayloadModel;
        }

        /// <summary>
        /// 创建群信息采集上报消息
        /// </summary>
        /// <param name="deviceCode">设备码</param>
        /// <param name="qqNumber">QQ号码</param>
        /// <param name="collectData">采集数据</param>
        /// <param name="collectTaskId">采集任务ID</param>
        /// <returns>采集上报消息模型</returns>
        public static CollectReportModel CreateGroupInfoCollectReport(
            string deviceCode,
            string qqNumber,
            List<object> collectData,
            string collectTaskId = null)
        {
            var payload = new CollectReportPayloadModel
            {
                CollectType = CollectTypeConstants.GROUP_INFO,
                QQNumber = qqNumber,
                CollectCount = collectData?.Count ?? 0,
                CollectData = collectData ?? new List<object>(),
                CollectTaskId = collectTaskId,
                BatchNumber = 1,
                TotalBatches = 1,
                IsLastBatch = true,
                TotalCollected = collectData?.Count ?? 0
            };

            return new CollectReportModel(deviceCode, payload);
        }

        /// <summary>
        /// 创建批量采集上报消息
        /// </summary>
        /// <param name="deviceCode">设备码</param>
        /// <param name="collectType">采集类型</param>
        /// <param name="qqNumber">QQ号码</param>
        /// <param name="collectData">采集数据</param>
        /// <param name="collectTaskId">采集任务ID</param>
        /// <param name="batchNumber">批次号</param>
        /// <param name="totalBatches">总批次数</param>
        /// <param name="isLastBatch">是否为最后一批</param>
        /// <param name="totalCollected">总采集数量</param>
        /// <returns>采集上报消息模型</returns>
        public static CollectReportModel CreateBatchCollectReport(
            string deviceCode,
            string collectType,
            string qqNumber,
            List<object> collectData,
            string collectTaskId,
            int batchNumber,
            int totalBatches,
            bool isLastBatch,
            int totalCollected)
        {
            var payload = new CollectReportPayloadModel
            {
                CollectType = collectType,
                QQNumber = qqNumber,
                CollectCount = collectData?.Count ?? 0,
                CollectData = collectData ?? new List<object>(),
                CollectTaskId = collectTaskId,
                BatchNumber = batchNumber,
                TotalBatches = totalBatches,
                IsLastBatch = isLastBatch,
                TotalCollected = totalCollected
            };

            return new CollectReportModel(deviceCode, payload);
        }
    }

    /// <summary>
    /// 群信息模型
    /// </summary>
    public class GroupInfoModel
    {
        /// <summary>
        /// 群号
        /// </summary>
        [JsonProperty("groupNumber")]
        public string GroupNumber { get; set; }

        /// <summary>
        /// 群名称
        /// </summary>
        [JsonProperty("groupName")]
        public string GroupName { get; set; }

        /// <summary>
        /// 成员数量
        /// </summary>
        [JsonProperty("memberCount")]
        public int MemberCount { get; set; }

        /// <summary>
        /// 加入时间戳（毫秒）
        /// </summary>
        [JsonProperty("joinTime")]
        public long JoinTime { get; set; }

        /// <summary>
        /// 角色（0-成员，1-管理员，2-群主）
        /// </summary>
        [JsonProperty("role")]
        public int Role { get; set; }

        /// <summary>
        /// 群公告
        /// </summary>
        [JsonProperty("announcement")]
        public string Announcement { get; set; }

        /// <summary>
        /// 群简介
        /// </summary>
        [JsonProperty("introduction")]
        public string Introduction { get; set; }

        /// <summary>
        /// 群分类
        /// </summary>
        [JsonProperty("category")]
        public string Category { get; set; }

        /// <summary>
        /// 群等级
        /// </summary>
        [JsonProperty("level")]
        public int Level { get; set; }

        /// <summary>
        /// 群创建时间戳（毫秒）
        /// </summary>
        [JsonProperty("createTime")]
        public long CreateTime { get; set; }

        /// <summary>
        /// 最后活跃时间戳（毫秒）
        /// </summary>
        [JsonProperty("lastActiveTime")]
        public long LastActiveTime { get; set; }

        /// <summary>
        /// 额外信息
        /// </summary>
        [JsonProperty("extraInfo")]
        public Dictionary<string, object> ExtraInfo { get; set; }
    }

    /// <summary>
    /// 群成员信息模型
    /// </summary>
    public class GroupMemberModel
    {
        /// <summary>
        /// 群号
        /// </summary>
        [JsonProperty("groupNumber")]
        public string GroupNumber { get; set; }

        /// <summary>
        /// QQ号码
        /// </summary>
        [JsonProperty("qqNumber")]
        public string QQNumber { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>
        [JsonProperty("nickname")]
        public string Nickname { get; set; }

        /// <summary>
        /// 群名片
        /// </summary>
        [JsonProperty("cardName")]
        public string CardName { get; set; }

        /// <summary>
        /// 角色（0-成员，1-管理员，2-群主）
        /// </summary>
        [JsonProperty("role")]
        public int Role { get; set; }

        /// <summary>
        /// 加入时间戳（毫秒）
        /// </summary>
        [JsonProperty("joinTime")]
        public long JoinTime { get; set; }

        /// <summary>
        /// 最后发言时间戳（毫秒）
        /// </summary>
        [JsonProperty("lastSpeakTime")]
        public long LastSpeakTime { get; set; }

        /// <summary>
        /// 性别（0-未知，1-男，2-女）
        /// </summary>
        [JsonProperty("gender")]
        public int Gender { get; set; }

        /// <summary>
        /// 年龄
        /// </summary>
        [JsonProperty("age")]
        public int Age { get; set; }

        /// <summary>
        /// 所在地
        /// </summary>
        [JsonProperty("location")]
        public string Location { get; set; }

        /// <summary>
        /// 是否为会员
        /// </summary>
        [JsonProperty("isVip")]
        public bool IsVip { get; set; }

        /// <summary>
        /// 会员等级
        /// </summary>
        [JsonProperty("vipLevel")]
        public int VipLevel { get; set; }

        /// <summary>
        /// 额外信息
        /// </summary>
        [JsonProperty("extraInfo")]
        public Dictionary<string, object> ExtraInfo { get; set; }
    }

    /// <summary>
    /// 好友信息模型
    /// </summary>
    public class FriendInfoModel
    {
        /// <summary>
        /// QQ号码
        /// </summary>
        [JsonProperty("qqNumber")]
        public string QQNumber { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>
        [JsonProperty("nickname")]
        public string Nickname { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [JsonProperty("remark")]
        public string Remark { get; set; }

        /// <summary>
        /// 性别（0-未知，1-男，2-女）
        /// </summary>
        [JsonProperty("gender")]
        public int Gender { get; set; }

        /// <summary>
        /// 年龄
        /// </summary>
        [JsonProperty("age")]
        public int Age { get; set; }

        /// <summary>
        /// 所在地
        /// </summary>
        [JsonProperty("location")]
        public string Location { get; set; }

        /// <summary>
        /// 是否为会员
        /// </summary>
        [JsonProperty("isVip")]
        public bool IsVip { get; set; }

        /// <summary>
        /// 会员等级
        /// </summary>
        [JsonProperty("vipLevel")]
        public int VipLevel { get; set; }

        /// <summary>
        /// 好友分组ID
        /// </summary>
        [JsonProperty("groupId")]
        public int GroupId { get; set; }

        /// <summary>
        /// 好友分组名称
        /// </summary>
        [JsonProperty("groupName")]
        public string GroupName { get; set; }

        /// <summary>
        /// 加为好友时间戳（毫秒）
        /// </summary>
        [JsonProperty("addTime")]
        public long AddTime { get; set; }

        /// <summary>
        /// 最后交流时间戳（毫秒）
        /// </summary>
        [JsonProperty("lastInteractTime")]
        public long LastInteractTime { get; set; }

        /// <summary>
        /// 额外信息
        /// </summary>
        [JsonProperty("extraInfo")]
        public Dictionary<string, object> ExtraInfo { get; set; }
    }
} 